<?php
    include "../../class/farm.class.php";
    include "../../class/crop.class.php";
    include "../../class/date.class.php";
    include "../../function/functionPHP.php";
    
    $farmID=$_POST["farmID"];
    $rvID=$_POST["rvID"];
    $farmClass=new farm($farmID);
    
    $dateClass=new date();
    $startDate=$dateClass->dateDisplayToSQL($_POST["startDate"]);
    $endDate=$dateClass->dateDisplayToSQL($_POST["endDate"]);
    
    if($_POST["cropID"]!=""){
        $arrTemp["startDate"]=$startDate;
        $arrTemp["endDate"]=$endDate;
        $arrTemp["cropID"]=$_POST["cropID"];
        $arrTemp["rvID"]=$_POST["rvID"];
        
        $cropClass=new crop($_POST["cropID"]);
        $cropClass->updateCrop($arrTemp);
    }else{
        $cropClass=new crop();
        $cropClass->addCrop($farmID,$startDate,$endDate,$rvID);
    }
    
    
    header("location:../../?page=member/crop/cropList&farmID=$farmID");